import java.util.ArrayList;
import java.util.Arrays;


public class DishRecommend {
	information info;
	Dishes[] dish1;
	Dishes likebest;
	int nt,nm;
	public DishRecommend(){
	}
	public DishRecommend(String Sno){
		info=new DatabaseOperate().infoquery("sNo",Sno).get(0);
		ArrayList<Dishes> dish=new DatabaseOperate().dishquery();
		likebest=new DatabaseOperate().dishquery("id",info.getLikebest()).get(0);
		System.out.println("该用户最喜欢吃："+likebest.getDname());
		String[] split=likebest.getMaterial().split(",");
		dish1=(Dishes[])dish.toArray(new Dishes[dish.size()]);
		for(int j=0;j<dish.size();j++){
			for(int m=0;m<4;m++){
				if(likebest.getTaste()[m]==dish1[j].getTaste()[m]){
				   nt++;
				}
			}
			String[] split1=dish1[j].getMaterial().split(",");
			for (int i=0;i<split1.length;i++){
				for(int k=0;k<split.length;k++){
					if(split1[i].equals(split[k]))
						nm++;
				}
			}
		dish1[j].setSimilarity((double)nm/split.length*44/93+(double)nt/4*49/93);
		System.out.println(dish1[j].getSimilarity());
		nt=0;nm=0;
		}
	}
	public Dishes[] topndishes(int n){
		Arrays.sort(dish1);
		Dishes[] topndishes=new Dishes[n];
		for(int i=0;i<n;i++){
			topndishes[i]=dish1[i];
			System.out.println("推荐："+dish1[i].getDname());
		}
		return topndishes;
	}
	public static void main(String[] args){
		new DishRecommend("2011212095").topndishes(10);
	}
}
